using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using InfraStructureLayer;
using WebControls;
using EntityLayer;
using BusinessLayer;

public partial class Admin_MultilanguageSettings : SFPage
{
entMultilanguageSettings insEntMultilanguageSettings = new entMultilanguageSettings();
    busMultilanguageSettings insBusMultilanguageSettings = new busMultilanguageSettings();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected bool sfdPages_NeedsDataSource()
    {
        sfdPages.SetData(CurrentContext.Pages, "PageDescription", "PageId");
        return false;
    }
    protected bool sfdLanguage_NeedsDataSource()
    {
        sfdLanguage.SetData(CurrentContext.Languages, "LanguageName", "LanguageId");
        return false;
    }
    protected void btnList_Click(object sender, EventArgs e)
    {
        if (sfdPages.Value.HasValue && sfdLanguage.Value.HasValue)
        {
            sfgMultilanguageSettings.LoadGridData();
        }
    }
    protected bool sfgMultilanguageSettings_NeedsDataSource()
    {
        if (sfdPages.Value.HasValue && sfdLanguage.Value.HasValue)
        {
            insEntMultilanguageSettings.PageId = sfdPages.Value.Value;
            insEntMultilanguageSettings.LanguageId = sfdLanguage.Value.Value;
            sfgMultilanguageSettings.SetData((DataTable)CurrentContext.Multilanguage[insEntMultilanguageSettings.ToString()]);

        }
        else
        {
            sfgMultilanguageSettings.SetData(null);
        }
        return false;
    }
    protected void btnNew_Click(object sender, EventArgs e)
    {
        this.Id = 0;
        this.OpenEditPanel();
    }
    protected void sfgMultilanguageSettings_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "EditData")
        {
            this.Id = Convert.ToInt32(e.CommandArgument);
            this.OpenEditPanel();
        }
        else if (e.CommandName == "DeleteData")
        {
            insEntMultilanguageSettings.MultiLanguageSettingId = Convert.ToInt32(e.CommandArgument);
            insBusMultilanguageSettings.DeleteMultilanguageSettingsByMultiLanguageSettingId(insEntMultilanguageSettings);
            if (insBusMultilanguageSettings.HasErrors)
            {
                MessageBoxShow(insBusMultilanguageSettings);
                return;
            }
            sfgMultilanguageSettings.LoadGridData();
            this.CloseEditPanel();
        }
    }
    public override void OpenEditPanel()
    {
        this.Clear(this.Master.FindControl("ContentPlaceHolderEdit"));
        base.OpenEditPanel();
        FillEditPanel();
    }
    private  void FillEditPanel()
    {
        if (this.Id!=0)
        {
            insEntMultilanguageSettings.MultiLanguageSettingId = this.Id;
            insBusMultilanguageSettings.SelectMultilanguageSettingsByMultiLanguageSettingId(insEntMultilanguageSettings);
            txtControlId.Text = insEntMultilanguageSettings.ControlId;
            txtControlText.Text = insEntMultilanguageSettings.ControlText;
        }
        else
        {
            txtControlId.Text = "";
            txtControlText.Text = "";
        }
    }

    public override void Save()
    {
        this.Validate();
        if (this.HasErrors)
        {
            MessageBoxShow(this);
            return;
        }
        insEntMultilanguageSettings.ControlId = txtControlId.Text;
        insEntMultilanguageSettings.ControlText = txtControlText.Text;
        insEntMultilanguageSettings.LanguageId = sfdLanguage.Value.Value;
        insEntMultilanguageSettings.PageId = sfdPages.Value.Value;
        base.Save();
    }
    public override void SaveNew()
    {
        insBusMultilanguageSettings.InsertMultilanguageSettings(insEntMultilanguageSettings);
        if (insBusMultilanguageSettings.HasErrors)
        {
            MessageBoxShow(insBusMultilanguageSettings);
            return;
        }
        base.SaveNew();
        sfgMultilanguageSettings.LoadGridData();
        CurrentContext.Multilanguage = null;
    }
    public override void SaveExisting()
    {
        insEntMultilanguageSettings.MultiLanguageSettingId = this.Id;
        insBusMultilanguageSettings.UpdateMultilanguageSettingsByMultiLanguageSettingId(insEntMultilanguageSettings);
        if (insBusMultilanguageSettings.HasErrors)
        {
            MessageBoxShow(insBusMultilanguageSettings);
            return;
        }
        base.SaveExisting();
        sfgMultilanguageSettings.LoadGridData();
        CurrentContext.Multilanguage = null;
    }
}
